<%--
  Created by IntelliJ IDEA.
  User: 494418174
  Date: 2020/3/3 0003
  Time: 9:35
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="icon" href="/favicon.ico">
    <link rel="stylesheet" href="/layui/css/layui.css">
    <link rel="stylesheet" href="/layui_ext/dtree/dtree.css">
    <link rel="stylesheet" href="/layui_ext/dtree/font/dtreefont.css">
</head>
<body>
<!-- 搜索条件开始 -->
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>查询条件</legend>
</fieldset>
<form class="layui-form" >
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">登录名称:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="loginName" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入登录名称" style="height: 30px;border-radius: 10px">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">登录IP:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="loginIp" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入登录IP" style="height: 30px;border-radius: 10px">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">起始时间:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="loginTime1" id="loginTime1" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入起始时间" style="height: 30px;border-radius: 10px">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">结束时间:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="loginTime2" id="loginTime2" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入结束时间" style="height: 30px;border-radius: 10px">
            </div>
        </div>
        <div class="layui-inline">
            <button class="layui-btn layui-btn-normal layui-btn-radius layui-btn-sm"  lay-submit lay-filter="formDemo">查询</button>
            <button type="reset" class="layui-btn layui-btn-warm layui-icon layui-icon-refresh layui-btn-radius layui-btn-sm">重置
            </button>
        </div>
    </div>
</form>
<%--显示列表--%>
<table id="logTable" lay-filter="logTable"></table>

<script id="toolbarLog" type="text/html">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="logDelChk">批量删除</button>
    </div>
</script>

<script id="barLog" type="text/html">
    <a class="layui-btn layui-btn-danger layui-btn-xs " lay-event="del">删除</a>
</script>
<script src="/layui/layui.js"></script>
<script>
    var logTable
    var index
    layui.extend({
        dtree: '/layui_ext/dtree/dtree'   // {/}的意思即代表采用自有路径，即不跟随 base 路径
    }).use(['table','form','layer','jquery','dtree','laydate'], function() {
        var table = layui.table
        var form = layui.form
        var layer = layui.layer
        var $ = layui.jquery
        var dtree = layui.dtree
        var laydate=layui.laydate
        laydate.render({
            elem:'#loginTime1'
            ,type:'datetime'
        });
        laydate.render({
            elem:'#loginTime2'
            ,type:'datetime'
        });
        // 初始table
        logTable = table.render({
            elem: "#logTable"
            , url: "/log/findLog"
            , page: {limit: 5, limits: [5, 10, 15]}
            , cellMinWidth: 80
            , toolbar: '#toolbarLog'
            , cols: [[ //表头
                {type: 'checkbox', fixed: 'left'}
                , {field: 'id', title: '日志ID', fixed: 'center'}
                , {field: 'loginName', title: '登录名称', fixed: 'center'}
                , {field: 'loginIp', title: '登录IP', fixed: 'center'}
                , {field: 'loginTime', title: '登录时间', fixed: 'center'}
                , {fixed: 'right', title: '操作', toolbar: '#barLog', width: 250}
            ]]
        })
        // 查询
        form.on("submit(formDemo)", function (data) {
            logTable.reload({
                url: "/log/findLog"
                , where: {
                    'loginName':data.field.loginName
                    ,'loginIp':data.field.loginIp
                    ,'loginTime1':data.field.loginTime1
                    ,'loginTime2':data.field.loginTime2

                }
                , page: {
                    curr: 1
                }
            })
            return false;
        })
        // 头部工具栏添加事件
        table.on('toolbar(logTable)',function(obj) {
            if(obj.event=="logDelChk"){
                logDelChk(obj)
            }
        })
        //监听行工具事件
        table.on('tool(logTable)', function(obj){
            var data = obj.data
            if(obj.event == "del"){
                del(data)
            }
        })
        function del(data){
            layer.confirm("您确定要删除"+ data.loginName +"数据么",function(ind){

                $.post("/log/delLog", {"id":data.id} ,function(d) {
                    layer.msg(d.msg)
                    // 刷新table数据
                    logTable.reload()

                })
                layer.close(ind)
            })

        }
        function logDelChk(obj) {
            var checkStatus=table.checkStatus(obj.config.id);
            var data=checkStatus.data
            if(data.length==0){
                layer.msg("请至少选择一个数据")
            }else {
                var ids=new Array()
                $.each(data,function (index,item) {
                    ids.push(item.id)
                })
                layer.confirm("你确定要删除"+data.length+"条数据么",function (ind) {
                    $.post("/log/logDelChk",{"ids":ids},function (r) {
                        layer.msg(r.msg)
                        logTable.reload()
                    })
                    layer.close(ind)
                })
            }
        }


    })
</script>
</body>
</html>
